package com.inspur.edp.web.formmetadata.i18n.component.strategy.i18nresourcestrategy;

import com.inspur.edp.lcm.metadata.api.entity.I18nResourceItem;
import com.inspur.edp.lcm.metadata.api.entity.I18nResourceItemCollection;
import com.inspur.edp.web.formmetadata.i18n.I18nResourceItemManager;
import com.inspur.edp.web.formmetadata.i18n.component.ComponentUtility;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.ComponentNameFactory;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.ComponentNameType;
import com.inspur.edp.web.formmetadata.i18n.component.strategy.namestrategy.IComponentNameStrategy;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * VUE输入类构件提取
 * @author wangzhiyuan
 */
public class ResponseToolbarI18nResourceStrategy extends AbstractI18nResourceStrategy {
    @Override
    protected String getComponentName(HashMap<String, Object> component)  {
        return null;
    }
    //提取VUE输入类，枚举项多语
    @Override
    protected I18nResourceItemCollection extractAttributeI18nResourceItemCollection(String i18nResourceItemBaseId, HashMap<String, Object> currentComponent) {
        I18nResourceItemCollection i18nResourceItemCollection = new I18nResourceItemCollection();
        HashMap<String, Object> buttons =(HashMap<String, Object>) currentComponent.get("editor");
        if(!buttons.isEmpty()&&buttons.containsKey("data")){
            List<Object> datas=(List<Object>) buttons.get("data");
            String currentComponentType = ComponentUtility.getInstance().getType(currentComponent);
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            for (Object o : datas) {
                HashMap<Object, Object> data = (HashMap<Object, Object>) o;
                String generatedComponentId =  currentComponentId + "/editor/data/" + String.valueOf(data.get("value"));
                I18nResourceItem footerButtonI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, generatedComponentId, String.valueOf(data.get("name")), String.valueOf(data.get("name")));
                this.addInCollection(i18nResourceItemCollection, footerButtonI18nResourceItem);

            }
        }
        if(!buttons.isEmpty()&&buttons.containsKey("placeholder")){

            String currentComponentType = ComponentUtility.getInstance().getType(currentComponent);
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);


                String generatedComponentId =  currentComponentId + "/editor/placeholder"  ;
                I18nResourceItem footerButtonI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, generatedComponentId, String.valueOf(buttons.get("placeholder")),String.valueOf(buttons.get("placeholder")));
                this.addInCollection(i18nResourceItemCollection, footerButtonI18nResourceItem);


        }
        if(buttons.containsKey("dialog")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            LinkedHashMap<String,Object> dialog= (LinkedHashMap<String, Object>) buttons.get("dialog");
            String title= (String) dialog.get("title");
            String childComponentId = currentComponentId +   "/dialog/title";
            I18nResourceItem dialogI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, childComponentId, title, title);
            this.addInCollection(i18nResourceItemCollection, dialogI18nResourceItem);

        }
        if(buttons.containsKey("formatValidation")){
            String currentComponentId = ComponentUtility.getInstance().getId(currentComponent);
            LinkedHashMap<String,Object> formatValidation= (LinkedHashMap<String, Object>) buttons.get("formatValidation");
            String message = (String) formatValidation.get("message");
            String childComponentId = currentComponentId +   "/formatValidation/message";
            I18nResourceItem dialogI18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, childComponentId, message, message);
            this.addInCollection(i18nResourceItemCollection, dialogI18nResourceItem);
        }




        return i18nResourceItemCollection;
    }
}